package nosqlconnect.menuActions;

import nosqlconnect.connection.Connection;

import org.eclipse.jface.action.Action;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;

public class MDeleteConnectionAction extends Action implements IWorkbenchAction{

	private Connection selectedConnection = null;
	
	public MDeleteConnectionAction(){
		setText("Delete");
		setToolTipText("Delete connection");
	}

	@Override
	public void dispose() {
		
	}
	
	public void run(){
		Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();  
		String dialogBoxTitle = "Message";
		String message = null;
		
		if (null == selectedConnection){
			message = "No connection selected!";
		}
		else {
			message = "Really delete "+selectedConnection.getName()+" ?";
		}
		
		MessageBox msgBox = new MessageBox(shell,SWT.ICON_QUESTION | SWT.YES | SWT.NO);
		msgBox.setMessage(message);
		msgBox.setText(dialogBoxTitle);
		
		if (SWT.YES == msgBox.open()){
			//TODO find a way to delete connection
		}
	}

	public Connection getSelectedConnection() {
		return selectedConnection;
	}

	public void setSelectedConnection(Connection selectedConnection) {
		this.selectedConnection = selectedConnection;
	}
}
